package com.example.demo.repository;

import com.example.demo.entity.Star;
import com.example.demo.entity.Post;
import com.example.demo.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface StarRepository extends JpaRepository<Star, Long> {

    //统计某个文章的收藏数
    Long countByPost(Post post);

    //检查用户是否收藏某篇文章
    boolean existsByPostAndUser(Post post, User user);
    Optional<Star> findByPostAndUser(Post post, User user);

}
